clear; clc;
load('data/recsys/movielen10m.mat');

para.tau = 1.01;
[row, col, val] = find(data);

[m, n] = size(data);

clear user item;

val = val - mean(val);
val = val/std(val);

idx = randperm(length(val));

traIdx = idx(1:floor(length(val)*0.5));
tstIdx = idx(ceil(length(val)*0.5): end);

clear idx;

traData = sparse(row(traIdx), col(traIdx), val(traIdx));
traData(size(data,1), size(data,2)) = 0;

para.test.row  = row(tstIdx);
para.test.col  = col(tstIdx);
para.test.data = val(tstIdx);
para.test.m = m;
para.test.n = n;

clear m n;

%% start testing
para.maxIter = 500;
para.decay = 0.8;
para.tol = 1e-2;
    
para.decay = 0.95;   
para.regType = 2;
para.maxR = 12;

switch(para.regType)
    case 1
        para.maxR = 3;
        lambda = 10;
%         lambda = 40;
        theta1 = lambda*2;
    case 2
        lambda = 3000;
        % lambda = 5000;
        theta1 = sqrt(lambda);
        para.maxR = 3;
    case 3
        lambda = 35;
%         lambda = 40;
        theta1 = 3;
end

method = 1;
t = tic;
para.speedup = 1;
[U, S, V, out{method}] = FastMatComp( traData, lambda, theta1, para );
Time(method) = toc(t);
RMSE(method) = MatCompRMSE( U, V, S, row(tstIdx), col(tstIdx), val(tstIdx));

method = 2;
t = tic;
para.speedup = 1;
[U, S, V, out{method}] = FastMatCompAcc( traData, lambda, theta1, para );
Time(method) = toc(t);
RMSE(method) = MatCompRMSE( U, V, S, row(tstIdx), col(tstIdx), val(tstIdx));

close all;

figure;
plot(out{1}.Time, out{1}.RMSE);
hold on;
plot(out{2}.Time, out{2}.RMSE);

figure;
plot(out{1}.Time, out{1}.obj);
hold on;
plot(out{2}.Time, out{2}.obj);




